package com.namecard.namecardapi.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.namecard.namecardapi.entity.DTO.CommentDto;
import com.namecard.namecardapi.entity.TComment;
import com.namecard.namecardapi.mapper.TCommentMapper;
import com.namecard.namecardapi.service.TCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TCommentServiceImpl extends ServiceImpl<TCommentMapper, TComment> implements TCommentService {

    @Autowired
    private TCommentMapper tCommentMapper;

    //发表评论
    @Override
    public int insertComment(CommentDto commentdto) {
        TComment tComment = new TComment();
        tComment.setCommodityId(commentdto.getCommodityId());
        tComment.setContent(commentdto.getContent());
        tComment.setUserName(commentdto.getUserName());
        int insert = tCommentMapper.insert(tComment);
        return insert;
    }

    //查出商品的评论
    @Override
    public IPage<TComment> selectPage(Page<TComment> pageParam, Long commodityId) {
        System.out.println(pageParam);
        System.out.println(commodityId);
        IPage<TComment> pageModel = baseMapper.selectPage(pageParam, commodityId);
        return pageModel;
    }
}
